﻿using System.Collections.Generic;
using facebook.Schema;

namespace facebook
{
	/// <summary>
	/// Facebook application api methods.
	/// </summary>
	public class notes
	{
		private readonly API _api;
		/// <summary>
		/// Public constructor for facebook.notes
		/// </summary>
		/// <param name="parent">Needs a connected API object for making requests</param>
		public notes(API parent)
		{
			_api = parent;
		}

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IList<note> get()
        {
            return get(0);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IList<note> get(long uid)
        {
            var parameterList = new Dictionary<string, string> { { "method", "facebook.notes.get" } };
            _api.AddOptionalParameter(parameterList, "uid", uid);

            var response = _api.SendRequest(parameterList);
            return !string.IsNullOrEmpty(response) ? notes_get_response.Parse(response).note : null;
        }
        /// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
        public long create(long uid, string title, string content)
		{
			var parameterList = new Dictionary<string, string> { { "method", "facebook.notes.create" } };
            _api.AddRequiredParameter(parameterList, "uid", uid);
            _api.AddRequiredParameter(parameterList, "title", title);
            _api.AddRequiredParameter(parameterList, "content", content);

			var response = _api.SendRequest(parameterList, !string.IsNullOrEmpty(_api.SessionKey));
			return !string.IsNullOrEmpty(response) ? notes_create_response.Parse(response).TypedValue : -1;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool edit(long note_id, string title, string content)
        {
            var parameterList = new Dictionary<string, string> { { "method", "facebook.notes.edit" } };
            _api.AddRequiredParameter(parameterList, "note_id", note_id);
            _api.AddRequiredParameter(parameterList, "title", title);
            _api.AddRequiredParameter(parameterList, "content", content);

            var response = _api.SendRequest(parameterList, !string.IsNullOrEmpty(_api.SessionKey));
            return !string.IsNullOrEmpty(response) ? notes_edit_response.Parse(response).TypedValue : false;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool delete(string title, string content)
        {
            return delete(0, title, content);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool delete(long uid, string title, string content)
        {
            var parameterList = new Dictionary<string, string> { { "method", "facebook.notes.delete" } };
            _api.AddOptionalParameter(parameterList, "uid", uid);
            _api.AddRequiredParameter(parameterList, "title", title);
            _api.AddRequiredParameter(parameterList, "content", content);

            var response = _api.SendRequest(parameterList, !string.IsNullOrEmpty(_api.SessionKey));
            return !string.IsNullOrEmpty(response) ? notes_delete_response.Parse(response).TypedValue : false;
        }
    }
}
